package cn.tedu.knows.faq.mapper;


import cn.tedu.knows.commons.model.Question;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author tedu.cn
 * @since 2022-03-04
 */
@Repository
public interface QuestionMapper extends BaseMapper<Question> {

    @Select("SELECT COUNT(*) FROM question\n" +
            "WHERE user_id=#{id} AND delete_status=0")
    int countQuestionsByUserId(Integer id);

    @Select("select count(*) from user_collect where user_id=#{id}")
    int countCollectByUserId(Integer id);

    @Select("SELECT q.* FROM question q\n" +
            "LEFT JOIN user_question uq ON  q.id=uq.question_id\n" +
            "WHERE uq.user_id=#{id} OR q.user_id=#{id}\n" +
            "ORDER BY q.createtime desc")
    List<Question> findTeacherQuestions(Integer userId);

}
